<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/album/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tuijian/inc.php");




//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;
	
	cgi::both($g_cgival["uid"], "uid", "");
	$g_cgival["uid"] = intval($g_cgival["uid"]);
	
	cgi::both($g_cgival["pcount"], "pcount", 12);
	$g_cgival["pcount"] = intval($g_cgival["pcount"]);
	
	cgi::both($g_cgival["type"], "type", "all");
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	$g_show["user_top_type"] = "my_feed";
	$g_show["hide_shadow"] = true;
	$type = $g_cgival["type"];
	$g_show["type"] = $type;
	$pcount = $g_cgival["pcount"];
	
	//登录相关
	$user_info = new user_info();
	$uid  = $g_cgival["uid"];
	$g_show["user_info"] = $user_info->get_user_info_by_uid($uid);
	$is_login = $user_info->is_logined();
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
		$g_show["is_logined"] = true;
		$g_show["current_user_info"] = $user_detail_info;
	}
	
	$uid_array[] = $uid;
	
	$db_user_feed = new db_user_feed();
	$list = $db_user_feed->get_user_feed_list_by_uids($uid_array);
	$count = $db_user_feed->get_user_feed_count_by_uids($uid_array);
	
	foreach($list as $key => $value)
	{
		$list[$key]["data_detail"] = unserialize($value['data_detail']);
		$list[$key]["data_detail"]["create_time"] = TimeFormatter::timeFormatShort($list[$key]["data_detail"]["create_time"]);
		
	}
	
	$g_show["count"] = $count;
	$g_show["list"] = $list;
	
	
	$max_page = page_bar::get_page_max($g_show["count"], $g_cgival["pcount"], $g_cgival["p"]);
	$page_bar_style = array(
			"curt"		=> $g_cgival["p"],
			"max"		=> $max_page,
			"key"		=> "p",
	);
	
	$g_show["page_bar"] = "<b>{$g_show["count"]}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar3($page_bar_style);
	
	
	$g_show["page_title"] = "{$g_show["user_info"]["user_nickname"]}的动态" ;
	$g_show["page_keywords"] = "{$g_show["user_info"]["user_nickname"]}的 动态" ;
	$g_show["page_desc"] = "{$g_show["user_info"]["user_nickname"]}的 动态" ;
	
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("user/user_feed.html");

	if($_GET["debug"])
	{
		echo "<pre>";
		print_r($g_show);
	}
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

